﻿<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title>librarybookinfo</title>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
      <style type="text/css">
        .btabs
        {
            border: 1px solid #8DB2E3;
            font-size: 12px;
            height: 31px;
            list-style-type: none;
            width: 100.2%;
            background-color: #E0ECFF;
        }
    </style>
    <script src="../../JS1/easyUI/jquery-1.7.2.min.js" type="text/javascript"></script>
    <script src="../../JS1/easyUI/jquery.easyui.min.js" type="text/javascript"></script>
    <script src="../../JS1/easyUI/locale/easyui-lang-zh_CN.js" type="text/javascript"></script>
    <script src="../../JS1/ljxpage.js" type="text/javascript"></script>
    <link href="../../JS1/easyUI/themes/default/easyui.css" rel="stylesheet" type="text/css" /> 
    <link href="../../JS1/easyUI/themes/icon.css" rel="stylesheet" type="text/css" />
    <link href="../../JS1/css/default.css" rel="stylesheet" type="text/css" />

    <script type="text/javascript">
        $(document).ready(function () {
            //定义功能按钮是否可见,如果不需要，可以将如下函数屏蔽
            setbutton();
        });

        //弹出信息窗口 title:标题 msgString:提示信息 msgType:信息类型 [error,info,question,warning]
        function msgShow(title, msgString, msgType) {
            $.messager.alert(title, msgString, msgType);
        }
        $(function () {
            InitGird(0);
            InitSearch();
            $('#ljxwin').dialog({
                closed: true,
                title: 'librarybookinfo'
            });
            
                                    $('#ISBN').combogrid({
                            panelWidth: 280,
                           multiple: false,
                           idField: 'ISBN',
                           textField: 'ISBN',
                         url: '../../myweb/ashx/librarybookinfo.ashx?type=combox&comboxname=ISBN',
                           columns: [[					 
                               { field: 'BookName', title: 'BookName', width: 100 },
                               { field: 'ISBN', title: 'ISBN', width: 100 }
                           ]],
                           onSelect: function () {
                               var g = $('#ISBN').combogrid('grid');	// get datagrid object
                               var r = g.datagrid('getSelected');	// get the selected row
                               //alert(r.字段名); //如果要给其它字段赋值，请参考此。$('#yinsuming').val(r.字段名);  
                           }
                       });

        });

        //初始化表格
        function InitGird(parsend) {
            $('#tab_list').datagrid({
                title: '图书入库', //表格标题
                url: '../../myweb/ashx/librarybookinfo.ashx?mysearch=' + parsend, //请求数据的页面
                //   sortName: '产品名称', //排序字段
                idField: 'id', //标识字段,主键
                iconCls: '', //标题左边的图标
                width: '100%', //宽度
                singleSelect: true,
                nowrap: false, //是否换行，True 就会把数据显示在一行里
                striped: true, //True 奇偶行使用不同背景色
                collapsible: false, //可折叠
                sortOrder: 'desc', //排序类型
                remoteSort: false, //定义是否从服务器给数据排序

                columns: [[
                         
                          { field: 'ISBN', title: '图书编号', width: $(this).width() * 0.166666666666667, align: 'center' },
                          { field: 'BarCodeId', title: '条形码编号', width: $(this).width() * 0.166666666666667, align: 'center' },
                          { field: 'RukuDate', title: '入库时间', width: $(this).width() * 0.166666666666667, align: 'center' },
                          { field: 'BookState', title: '书本状态（已借出/未借出/已遗失）', width: $(this).width() * 0.166666666666667, align: 'center' },
                          { field: 'Operation', title: '操作人', width: $(this).width() * 0.166666666666667, align: 'center' }

                ]],
                onDblClickCell: function () {
                    edit();
                },
                queryParams: { "action": "query2" },
                pagination: true, //是否开启分页
                pageNumber: 1, //默认索引页
                pageSize: 40, //默认一页数据条数
                rownumbers: true //行号
            });

        }
        //初始化搜索框
        function InitSearch() {
            $("#ipt_search").searchbox({
                width: 200,
                iconCls: 'icon-save',
                searcher: function (val, name) {
                    $('#tab_list').datagrid('options').queryParams.search_type = name;
                    $('#tab_list').datagrid('options').queryParams.search_value = val;
                    $('#tab_list').datagrid('reload');
                },
                prompt: '请输入要查询的账号'
            });
        }

        function closeljxwin() {
            $('#ljxwin').dialog('close');
        }
        function add() {
                        $('#ISBN').val('');
            $('#BarCodeId').val('');
            $('#RukuDate').val('');
            $('#BookState').val('');
            $('#Operation').val('');

            $('#HdId').val('');
            $('#ljxwin').dialog('open');
        }
        function edit() {
            var node = $('#tab_list').datagrid('getSelected');
            if (node) {
                $('#HdId').val(node.Id);

                $.post('../../myweb/ashx/librarybookinfo.ashx?type=edit&Id=' + $('#HdId').val(), function (msg) {
                    var str = msg.split('|');

                                        $('#ISBN').combogrid('setValue', str[1]);
                    $('#BarCodeId').val(str[2]);
                    $('#RukuDate').val(str[3]);
                    $('#BookState').val(str[4]);
                    $('#Operation').val(str[5]);

                });
                $('#ljxwin').dialog('open');
            } else {
                msgShow('系统提示', '请选择要编辑的产品', 'error');
            }
        }
        function del() {
            var node = $('#tab_list').datagrid('getSelected');
            if (node) {
                $('#HdId').val(node.Id);

                $.messager.confirm('系统提示', '删除后不可恢复，确定要删除？', function (i) {
                    if (i) {
                       
                        $.post('../../myweb/ashx/librarybookinfo.ashx?type=del&Id=' + $('#HdId').val(), function (msg) {
                            if (msg == "true") {
                                msgShow('系统提示', '恭喜，记录删除成功！', 'info');
                                $('#tab_list').datagrid('reload');
                            }
                            else { msgShow('系统提示', '只有未借出的书本才能删除！', 'info'); }
                        });
                    }
                })
            } else {
                msgShow('系统提示', '请选择要编辑的记录', 'error');
            }
        }
        //添加/保存 信息
        function saveData() {
                            var ISBN = $('#ISBN').combogrid('getValues');
                var BarCodeId = $('#BarCodeId').val();
                var RukuDate = $('#RukuDate').val();
                var BookState = $('#BookState').val();
                var Operation = $('#Operation').val();

            var Id = $('#HdId').val();
            $.post('../../myweb/ashx/librarybookinfo.ashx?type=save&Id=' + Id  + '&ISBN=' + encodeURI(ISBN) + '&BarCodeId=' + encodeURI(BarCodeId) + '&RukuDate=' + encodeURI(RukuDate) + '&BookState=' + encodeURI(BookState) + '&Operation=' + encodeURI(Operation), function (msg) {
                msgShow('系统提示', '编辑成功', 'info');
                $('#ljxwin').dialog('close');
                $('#tab_list').datagrid('reload');
            });
        }

    </script>
</head>
<body  style="background:white">
    <form>
    <input id="HdId" type="hidden" />
    <!--工具栏-->
    <div class="btabs">
         <table width="100%">
            <tr>
                <td style="text-align: left;">
                    <table>
                        <tr>
                            <td id="ljxfun5" >
                                <div class="datagrid-btn-separator"></div>
                                <a class="easyui-linkbutton" iconcls="icon-help" plain="true" href="#" target="_blank">帮助</a>
                            </td>
                            <td id="ljxfun1">
                                <a class="easyui-linkbutton" iconcls="icon-add1" plain="true" onclick="add()">入库</a>
                            </td>
                           
                            <td id="ljxfun3">
                                <div class="datagrid-btn-separator"></div>
                                <a class="easyui-linkbutton" iconcls="icon-remove" plain="true" onclick="del()">出库</a>
                            </td>
                            <td> 
                                <div class="datagrid-btn-separator"></div>   &nbsp;  <a  class="easyui-linkbutton" iconcls="icon-pencil" plain="true"  onclick="InitGird(1)">显示全部</a> 
                            </td>

                        </tr>
                    </table>
                           
                </td>
                <td style="text-align: right; padding-right: 2px"  id="ljxfun4">
                      <input id="ipt_search" menu="#search_menu" />
                    <div id="search_menu" style="width:120px">
                        <div name="ISBN">
                            图书编号</div>
                        <div name="BarCodeId">
                            条形码编号</div>
                        <div name="BookState">
                            书本状态</div>
                        <div name="Operation">
                            操作人</div>
                    </div>

                </td>
            </tr>
        </table>
    </div>
    <div id="div2" style="width: 100.5%">         
        <table id="tab_list"  style="height: auto" >
        </table>         
    </div>
     
    <div id="ljxwin" icon="icon-save" style="padding: 5px; width: 460px;">
        <div id="divU">
            <table cellpadding="0" cellspacing="1px" border="0" style="width: 100%;" bgcolor="b5d6e6">
                <tr style="background-color: White; height: 32px;">
                    <td style="width: 80px; padding-left: 5px">
                        图书编号
                    </td>
                    <td style="padding: 5px">
                                    <select id="ISBN"  style="width: 200px">
                                    </select>
                    </td>
                </tr>
                <tr style="background-color: White; height: 32px;">
                    <td style="width: 80px; padding-left: 5px">
                        条形码编号
                    </td>
                    <td style="padding: 5px">
                        <input id="BarCodeId" type="text" style="border: 1px solid #8DB2E3; width: 200px; height: 20px" placeholder="自动生成" readonly="true" />
                    </td>
                </tr>
                <tr style="background-color: White; height: 32px;">
                    <td style="width: 80px; padding-left: 5px">
                        入库时间
                    </td>
                    <td style="padding: 5px">
                        <input id="RukuDate" type="Text" style="border: 1px solid #8DB2E3; width: 200px; height: 20px" readonly="true" placeholder="自动生成 " />
                    </td>
                </tr>
                <tr style="background-color: White; height: 32px;">
                    <td style="width: 80px; padding-left: 5px">
                        书本状态
                    </td>
                    <td style="padding: 5px">
                        <select id="BookState" type="text" style="border: 1px solid #8DB2E3; width: 200px; height: 20px" >
                            <option>未借出</option>
                          

                        </select>
                    </td>
                </tr>
                                 
            </table>
        </div>
        <div region="south" border="false" style="text-align: right; height: 24px; line-height: 24px;">
            <a id="A3" class="easyui-linkbutton" onclick="saveData()" icon="icon-ok" href="javascript:void(0)">
                确定</a> <a id="A4" class="easyui-linkbutton" onclick="closeljxwin()" icon="icon-cancel"
                    href="javascript:void(0)">取消</a>
        </div>
    </div>
    </form>
</body>
</html>
